package HOT100;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author 是阿秋啊
 * @date 2022/09/24 16:04
 **/
public class meituan1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] strs = new String[n];
        for (int i = 0; i < strs.length; i++) {
            strs[i] = sc.next();
        }
        for (String str : strs) {
            Map<Character,Integer> map = new HashMap<>();
            for (int i = 0; i < str.length(); i++) {
                map.put(str.charAt(i),map.getOrDefault(str.charAt(i),0)+1);
            }
            int len = 0;
            int max = 0;
            for (Map.Entry<Character, Integer> entry : map.entrySet()) {
                if (entry.getValue() % 2 == 0) {
                    len+=entry.getValue();
                }else {
                    if (entry.getValue() <= max) {
                        len+=(entry.getValue() / 2) * 2;
                    }else {
                        len+=(max / 2) * 2;
                        max = entry.getValue();
                    }
                }
            }
            len+=max;
            System.out.println(len);
        }
    }
}